﻿using B.S.XZYData.Domain.Inventory;
using B.S.XZYData.Domain.RBAC;
using B.S.XZYData.Domain.XZY;
using B.S.XZYData.Domain.ZSH;
using B.S.XZYData.Domain.ZSHH;
using B.S.XZYData.Domain.LJC;
using SqlSugar;

namespace B.S.XZYData.Infrastructure
{
    /// <summary>
    /// 数据库上下文
    /// </summary>
    public class MyDbContext : SqlSugarClient
    {
        public MyDbContext(ConnectionConfig config) : base(config)
        {
            // 配置SqlSugar
            this.Aop.OnLogExecuting = (sql, pars) =>
            {
                Console.WriteLine($"SQL: {sql}");
                if (pars != null && pars.Any())
                {
                    Console.WriteLine($"Parameters: {string.Join(",", pars.Select(it => it.ParameterName + ":" + it.Value))}");
                }
            };
            
            // 配置实体映射
            this.CodeFirst.SetStringDefaultLength(200);
        }
        #region 徐紫阳业务模块实体
        /// <summary>
        /// 权限实体
        /// </summary>
        public ISugarQueryable<PermissionModel> PermissionModel => this.Queryable<PermissionModel>();

        /// <summary>
        /// 角色实体
        /// </summary>
        public ISugarQueryable<RoleModel> RoleModel => this.Queryable<RoleModel>();

        /// <summary>
        /// 权限角色中间实体
        /// </summary>
        public ISugarQueryable<PermissionRoleModel> PermissionRoleModel => this.Queryable<PermissionRoleModel>();

        /// <summary>
        /// 用户实体
        /// </summary>
        public ISugarQueryable<AccountModel> AccountModel => this.Queryable<AccountModel>();

        /// <summary>
        /// 用户角色中间实体
        /// </summary>
        public ISugarQueryable<AccountRoleModel> AccountRoleModel => this.Queryable<AccountRoleModel>();

        /// <summary>
        /// 班组主表实体
        /// </summary>
        public ISugarQueryable<Team> Team => this.Queryable<Team>();

        /// <summary>
        /// 班组成员子表实体
        /// </summary>
        public ISugarQueryable<TeamMember> TeamMember => this.Queryable<TeamMember>();

        /// <summary>
        /// 销售订单主表实体
        /// </summary>
        public ISugarQueryable<SalesOrder> SalesOrder => this.Queryable<SalesOrder>();

        /// <summary>
        /// 销售订单产品明细子表实体
        /// </summary>
        public ISugarQueryable<SalesOrderProduct> SalesOrderProduct => this.Queryable<SalesOrderProduct>();


        #endregion

        #region 赵士恒业务模块实体
        /// <summary>
        /// 工序表实体
        /// </summary>
        public ISugarQueryable<Process> Process => this.Queryable<Process>();

        /// <summary>
        /// 工序采集数据表实体
        /// </summary>
        public ISugarQueryable<ProcessCollectionData> ProcessCollectionData => this.Queryable<ProcessCollectionData>();

        /// <summary>
        /// 装配工单表实体
        /// </summary>
        public ISugarQueryable<AssemblyWorkOrder> AssemblyWorkOrder => this.Queryable<AssemblyWorkOrder>();

        /// <summary>
        /// 装配工单产品明细表实体
        /// </summary>
        public ISugarQueryable<AssemblyWorkOrderProductDetail> AssemblyWorkOrderProductDetail => this.Queryable<AssemblyWorkOrderProductDetail>();

        /// <summary>
        /// 任务表实体
        /// </summary>
        public ISugarQueryable<Domain.ZSHH.Task> Task => this.Queryable<Domain.ZSHH.Task>();

        /// <summary>
        /// 产量统计表实体
        /// </summary>
        public ISugarQueryable<ProductionStatistics> ProductionStatistics => this.Queryable<ProductionStatistics>();
        #endregion

        #region 樊煜婷业务模块实体
        /// <summary>
        /// 余额实体
        /// </summary>
        public ISugarQueryable<BalanceModel> BalanceModel => this.Queryable<BalanceModel>();
        /// <summary>
        /// 库存收发明细
        /// </summary>
        public ISugarQueryable<DetailsModel> DetailsModel => this.Queryable<DetailsModel>();
        /// <summary>
        /// 物料清单实体
        /// </summary>
        public ISugarQueryable<InventoryListModel> InventoryListModel => this.Queryable<InventoryListModel>();
        /// <summary>
        /// 出库单实体
        /// </summary>
        public ISugarQueryable<OutboundModel> OutboundModel => this.Queryable<OutboundModel>();
        /// <summary>
        /// 入库单实体
        /// </summary>
        public ISugarQueryable<Warehousingmodel> WarehousingModel => this.Queryable<Warehousingmodel>();
        #endregion

        #region 张诗晗业务模块实体
        /// <summary>
        /// 不良品项主数据
        /// </summary>
        public ISugarQueryable<Defective> Defective => this.Queryable<Defective>();

        /// <summary>
        /// 工序生产记录 (暂时注释，因为类不存在)
        /// </summary>
        // public ISugarQueryable<ProcessProductionRecord> ProcessProductionRecord => this.Queryable<ProcessProductionRecord>();

        /// <summary>
        /// 报工主表
        /// </summary>
        public ISugarQueryable<WorkReport> WorkReport => this.Queryable<WorkReport>();

        /// <summary>
        /// 报工-不良品项子表
        /// </summary>
        public ISugarQueryable<WorkReportDefectiveItem> WorkReportDefectiveItem => this.Queryable<WorkReportDefectiveItem>();

        /// <summary>
        /// 流程模版定义
        /// </summary>
        public ISugarQueryable<WorkflowDefinitionModel> WorkflowDefinitionModel => this.Queryable<WorkflowDefinitionModel>();

        /// <summary>
        /// 流程业务实例
        /// </summary>
        public ISugarQueryable<WorkflowInstanceModel> WorkflowInstanceModel => this.Queryable<WorkflowInstanceModel>();

        /// <summary>
        /// 审批记录
        /// </summary>
        public ISugarQueryable<AuditModel> AuditModel => this.Queryable<AuditModel>();
        #endregion


        #region 李嘉诚业务模块实体
        /// <summary>
        /// 工艺路线主表实体
        /// </summary>
        public ISugarQueryable<RouteModel> RouteModel => this.Queryable<RouteModel>();

        /// <summary>
        /// 工艺路线工序表实体
        /// </summary>
        public ISugarQueryable<RouteStepModel> RouteStepModel => this.Queryable<RouteStepModel>();

        /// <summary>
        /// 工单主表实体
        /// </summary>
        public ISugarQueryable<WorkOrderModel> WorkOrderModel => this.Queryable<WorkOrderModel>();

        /// <summary>
        /// 工单工序表实体
        /// </summary>
        public ISugarQueryable<WorkOrderProcessModel> WorkOrderProcessModel => this.Queryable<WorkOrderProcessModel>();

        /// <summary>
        /// 工单分配表实体
        /// </summary>
        public ISugarQueryable<WorkOrderAssignModel> WorkOrderAssignModel => this.Queryable<WorkOrderAssignModel>();

        /// <summary>
        /// 工单汇报表实体
        /// </summary>
        public ISugarQueryable<WorkOrderReportModel> WorkOrderReportModel => this.Queryable<WorkOrderReportModel>();

        /// <summary>
        /// 生产计划主表实体
        /// </summary>
        public ISugarQueryable<PlanModel> PlanModel => this.Queryable<PlanModel>();

        /// <summary>
        /// 生产计划项目表实体
        /// </summary>
        public ISugarQueryable<PlanItemModel> PlanItemModel => this.Queryable<PlanItemModel>();

        /// <summary>
        /// 产品信息表实体
        /// </summary>
        public ISugarQueryable<ProductModel> ProductModel => this.Queryable<ProductModel>();
        #endregion
    }
}